﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.Repository.Interface.Ms;

namespace VisionCloud.Domain.Repository.Implement.Ms
{
    public class MsManualMeasureSummaryItemsRepository : BaseRepository<MsManualMeasureSummaryItems>, IMsManualMeasureSummaryItemsRepository
    {
        public async Task<bool> HasMeasureItemSummryData(Guid taskId)
        {
            var result = await (from a in Db.MsManualMeasureSummaryItems
                                where a.TaskId == taskId
                                && !string.IsNullOrEmpty(a.ActualMeasurementPoints)
                                && !string.IsNullOrEmpty(a.ExplosionPoints)
                                select a
             ).AsNoTracking().ToListAsync().ConfigureAwait(false);
            if (result != null && result.Count > 0)
            {
                return true;
            }
            return false;
        }

        public async Task RemoveMeasureItemSummryData(Guid taskId)
        {
            var result = await (from a in Db.MsManualMeasureSummaryItems
                                where a.TaskId == taskId
                                select a).AsNoTracking().ToListAsync().ConfigureAwait(false);

            this.RemoveRange(result);
        }
    }
}